﻿//TextView.h

#ifndef  TEXTVIEW_H_
#define  TEXTVIEW_H_
#pragma once
#include "DATATYPE.h"
#include <QListWidget>
#include <QStringList>
#include <QTimer>
#include <QMenu>
#include <QMouseEvent>
#include <QEvent>
#include "RCG_DBDefine.h"
class QObject;

enum POPTYPE
{
	TXT_POPTYPE_CLEARTEXT				=1,			//清空显示	
	TXT_POPTYPE_NUM100					,			//设置
	TXT_POPTYPE_NUM200					,
	TXT_POPTYPE_NUM500					,
	TXT_POPTYPE_NUM1000					,
	TXT_POPTYPE_AUTOROLL				,
	TXT_POPTYPE_SAVETOFILE							//保存到文本	
};

enum MAX_LINE_NUME
{
	MAX_LINE_NUME_100				=100,
	MAX_LINE_NUME_200				=200,
	MAX_LINE_NUME_500				=500,
	MAX_LINE_NUME_1000				=1000
};

#define		TXT_DATA_FLAG_INFO				0			//提示内容
#define		TXT_DATA_FLAG_WARN				1			//警告内容
#define		TXT_DATA_FLAG_ERRO				2			//出错内容
#define		TXT_DATA_FLAG_SEND				3			//发送内容
#define		TXT_DATA_FLAG_RECV				4			//接收内容


#define	TXT_MAX_TEXT_BUFF_LEN				1024		//文本显示内存最大长度

#define TXT_MAX_CHAR_COUNT					200

class TextView : public QListWidget
{
   Q_OBJECT

public:
	TextView(QString ProcNamestr, QWidget * parent = 0);
	~TextView(void);

	//	显示数据报文
	void	AddCommBuffToView(XCHAR buff[], XUSHORT len, XUCHAR DataFlag=TXT_DATA_FLAG_INFO);

	//	添加显示信息
	void	AddCommBuffToView(QString MsgInfoStr, XUCHAR DataFlag=TXT_DATA_FLAG_INFO);
	
	//添加显示信息
	void	AddCommBuffToView(QStringList NewStrLst);

	//设置进程名字，用来设置保存文件名
	void	SetTextFileProcessName(QString ProcNamestr){m_ProcNameStr = ProcNamestr;};

protected:
	void	AddrStringToShow();

	void	AddTempToLst();
	void	setupPopMenuBar();
	void	RemoveExcessListStr(XINT RemoveNum);
	void	RemoveExcessItem(XINT RemoveNum);

protected:
	void	mousePressEvent(QMouseEvent *event);
	void	WriteDataToFile(QString InfoStr);
private slots:
	void	TimerProc_Show();

	void	upDateMenu(QPoint point); 
	void	OnClearText();
	void	OnSetLine100();
	void	OnSetLine200();
	void	OnSetLine500();
	void	OnSetLine1000();
	void	OnSetAutoRoll();
	void	OnSavetoFile();

signals:
	void	ViewPopMenu_Signal(QPoint curPoint);


private:
	QTimer*		m_TimerShow;
	XINT		m_MaxLineNum;			//最大行数
	XINT		m_CurLineNum;			//当前行数
	
 	XCHAR		m_TempBuff[TXT_MAX_CHAR_COUNT+1];
	XBOOL8		m_bReading;
	XBOOL8		m_bWritting;
	XBOOL8		m_bClearing;
	QStringList	m_TempLst;
	QStringList	m_TextLst;
	XUINT		m_CountNum;
	QMenu		*m_RighMenu;   
	XBOOL8		m_bAutoRoll;
	QString     m_ProcNameStr;
	QString     m_AllFileNameStr;
//	XUINT		m_LastTime;
//	XINT		m_IndexCount;
};



//////////////////////////////////////////////////////////////////////////
#endif